package com.example.sjc715.login


import android.util.Log
import android.widget.Toast
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.commonlibrary.mvi.BaseView
import com.example.sjc715.R
import com.example.sjc715.databinding.ActivityLoginBinding
import com.tencent.mmkv.MMKV
import com.umeng.socialize.ShareAction
import com.umeng.socialize.bean.SHARE_MEDIA
import com.umeng.socialize.media.UMWeb
import okhttp3.internal.notify
@Route(path = "/mine/login")
class LoginActivity : BaseView<ActivityLoginBinding,LoginViewModel>() {
    val user by lazy {
        mutableMapOf<String,String>()
    }
    override fun initData() {
        viewModel.state.observe(this@LoginActivity){
            when(it){
                is LoginState.LoginSuccess->{
                    Toast.makeText(this, "登陆成功", Toast.LENGTH_SHORT).show()
                    val mmkv = MMKV.defaultMMKV()
                    mmkv.encode("a", "123")
//                    encode.notify()
                    ARouter.getInstance().build("/login/bo").navigation()
                }
                is LoginState.Failure->{
                    Toast.makeText(this, "登陆失败", Toast.LENGTH_SHORT).show()
                    Log.d("---", "initData: ${it.error}")
                }
            }
        }
    }

    override fun initView() {
        binding.map = user
        binding.btn.setOnClickListener {
            viewModel.intent.trySend(LoginIntent.LoginI(user["password"]?:"",user["username"]?:""))
        }
        binding.qq.setOnClickListener {
            val  web = UMWeb("https://www.baidu.com/");
            web.setTitle("This is music title");//标题
//                web.setThumb(thumb);//缩略图
            web.setDescription("my description");//描述
            ShareAction(this)
                .withMedia(web)
                .setDisplayList(SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN)
                .open();
        }
    }

}